package org.jeecg.modules.manage.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.manage.entity.CaishuiTaskSettleItem;

import java.util.List;

/**
 * @Description: 任务结算详情
 * @Author: yfkj
 * @Date:   2023-02-20
 * @Version: V1.0
 */
@InterceptorIgnore(tenantLine = "true")
public interface MCaishuiTaskSettleItemMapper extends BaseMapper<CaishuiTaskSettleItem> {

	/**
	 * 通过主表id删除子表数据
	 *
	 * @param mainId 主表id
	 * @return boolean
	 */
	public boolean deleteByMainId(@Param("mainId") String mainId);

  /**
   * 通过主表id查询子表数据
   *
   * @param mainId 主表id
   * @return List<CaishuiTaskSettleItem>
   */
	public List<CaishuiTaskSettleItem> selectByMainId(@Param("mainId") String mainId);

	/**
	 * 获取该身份证号本月下发总额
	 * @param idCard
	 * @return
	 */
	@Select("SELECT IFNULL(SUM(money),0.00) FROM caishui_task_settle_item WHERE DATE_FORMAT(issued_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m') AND `status` = 2 AND id_card = #{idCard}")
	double getIssuedAmountTotal(@Param("idCard") String idCard);

	/**
	 * 获取该身份证号本月服务费差额总额
	 * @param idCard
	 * @return
	 */
	@Select("SELECT IFNULL(SUM(service_fee_differ),0.00) FROM caishui_task_settle_item WHERE DATE_FORMAT(issued_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m') AND `status` = 2 AND id_card = #{idCard}")
	double getServiceFeeDifferTotal(@Param("idCard") String idCard);

}
